/**
 * 
 */
package com.asdf.tests;

import java.util.Random;

/**
 * Random string generator.
 * Can be used as both generator (e.g. {@link #get()}) 
 * and random string entity (e.g. {@link #RandomString()}, then {@link #toString()}) 
 * @author ilia
 */
public class RandomString
{
	static final int DEFAULT_LENGTH = 10;
	static String DEFAULT_CHARS = "abcdefghijklmonpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	static Random r = new Random(42);

	public static String get() {
		return get(DEFAULT_LENGTH, DEFAULT_CHARS);
	}
	
	public static String get(int length) {
		return get(length, DEFAULT_CHARS);
	}

	public static String get(int length, String chars) {
		char[] buf = new char[length];
		for (int i=0; i<buf.length; i++) {
			buf[i] = chars.charAt(r.nextInt(chars.length()));
		}
		return new String(buf);
	}

	
	String val;

	RandomString(int len, String chars) {
		val = get(len, chars);
	}
	
	RandomString(int len) {
		val = get(len);
	}
	
	public RandomString() {
		val = get();
	}
	
	public String toString() {
		return val;
	}
}
